<?php
// +----------------------------------------------------------------------
// | ThinkBLOG (Build on ThinkPHP)
// +----------------------------------------------------------------------
// | @link ( http://www.yurnero.net )
// +----------------------------------------------------------------------
// | @licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | @author nicholas <nicholasinlove@126.com>
// +----------------------------------------------------------------------
// | $Id: UsersAction.class.php 146 2012-04-28 09:29:30Z nicholasinlove1986@gmail.com $
// +----------------------------------------------------------------------


class UsersAction extends AdminBaseAction {
	
	/**
	 * Users 模型句柄
	 *
	 * @access public
	 * @var string
	 */
	public $dao;
	
	public function _initialize() {
		
		parent::_initialize ();
		
		$this->dao = D ( 'Users' );
	}
	
	public function profile() {
		
		if (! empty ( $this->r->action )) {
			
			$meta = $this->r->from ( 'admin_color', 'show_admin_bar_front', 'show_admin_bar_admin' );
			
			$meta ['show_admin_bar_front'] = empty ( $meta ['show_admin_bar_front'] ) ? 0 : 1;
			$meta ['show_admin_bar_admin'] = empty ( $meta ['show_admin_bar_admin'] ) ? 0 : 1;
			
			if (false === $this->dao->create ()) {
				$this->assign ( 'error', $this->dao->getError () );
			} else {
				$this->dao->meta = serialize ( $meta );
				
				if (false !== $this->dao->save ()) {
					redirect ( __SELF__ );
				} else {
					$this->assign ( 'error', '更新失败' );
				}
			}
		}
		
		$this->assign ( 'ur_here', array ('text' => '个人资料', 'action' => 'users' ) );
		$this->assign ( 'vo', $this->dao->getByUserid ( $this->_getUserId () ) );
		$this->display ();
	}
	
}